package com.yqd.lesson.actor.four

import scala.concurrent.duration._
import akka.actor.{ActorRef, ActorSystem, Kill, PoisonPill}
import com.yqd.lesson.actor.four.Receiver.{props, system}

/*
  Actor SelectActor become unbecome watch
 */
object Main extends App{

  //用户创建的顶级actor的监管者
  val system: ActorSystem = ActorSystem("akka")
  val receiver = system.actorOf(props,"receiver");

  //创建akka://helloAkka/user/printerActor
  val receiverPath = "/user/receiver"
  val sender: ActorRef = system.actorOf(Sender.props(receiverPath), "sender")

  var num = 0;

  import system.dispatcher
  system.scheduler.schedule(1.second,3.second){
    if(num > 10){
      receiver ! Kill
    }
    sender ! "msg"
    num = num + 1;
  }

  //system.terminate();
}
